package org.apache.commons.graph.bean

import com.gitee.wsl.text.format.format
import org.apache.commons.graph.utils.Objects
import kotlin.jvm.JvmField


open class LabeledEdge<V>(
    @JvmField val label: String,
    source: V, target: V
): DefaultEdge<V>(source,target){

    /**
     * {@inheritDoc}
     */
    override fun equals(obj: Any?): Boolean {
        if (this === obj) {
            return true
        }

        if (obj == null || this::class != obj::class) {
            return false
        }

        val other = obj as LabeledEdge<*>
        if (source != other.source) return false
        if (target != other.target) return false

        return Objects.eq(label, other.label)
    }

    /**
     * {@inheritDoc}
     */
    override fun hashCode(): Int {
        return Objects.hash(1, 31, label)
    }

    /**
     * {@inheritDoc}
     */
    override fun toString(): String {
        return String.format("%s()", label)
    }

}